import java.util.Stack;

public class Solution {
    public static boolean backspaceCompare(String s, String t) {
        char[] arr1 = s.toCharArray();
        char[] arr2 = t.toCharArray();
        Stack<Character> stack1;
        stack1 = new Stack<>();
        Stack<Character> stack2 = new Stack<>();
        for (int i = 0; i < arr1.length; i++) {
            if (arr1[i] != '#') {
                stack1.push(arr1[i]);
            } else {
                if (!stack1.isEmpty()) {
                    stack1.pop();
                }
            }
        }
        for (int i = 0; i < arr2.length; i++) {
            if (arr2[i] != '#') {
                stack2.push(arr2[i]);
            } else {
                if (!stack2.isEmpty()) {
                    stack2.pop();
                }
            }
        }
        if (stack1.size() != stack2.size()) {
            return false;
        }
        while(!stack1.isEmpty()) {
            char ch1 = stack1.pop();
            char ch2 = stack2.pop();
            if (ch1 != ch2) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        String s = "a#c";
        String t = "b";
        boolean flg = backspaceCompare(s,t);
        System.out.println(flg);
        System.out.println("adasda");
    }
}
